package global.io;
import java.io.BufferedReader;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.io.Reader;
import java.io.Writer;
import java.util.Scanner;

/**
 *
 * @author saltcoffee
 */
public class ReadWrite {
	private static Scanner scan;
	private String path;
	public void setpath(String path){
		this.path=path;
	}
		public void nhap(){
			
			
			try {
				System.out.println("nhap vao duong dan chua file");
				scan=new Scanner(System.in);
				path=scan.nextLine();
	                        //String a;
	                        //scan = new Scanner(System.in);
	                        //System.out.println("Moi ban nhap vao ten file: ");
	                        //a=scan.nextLine();
				FileInputStream fin = new FileInputStream(path);
				Reader r= new InputStreamReader(fin, "UTF8");
	                        StringBuilder text;
	                        Writer out;
	                        
	                        
	                        try (BufferedReader br = new BufferedReader(r)) {
	                            text = new StringBuilder();
	                            String line;
	                            String b;
	                            System.out.println("Nhap ten file dau ra: ");
	                            b=scan.nextLine();
	                            FileOutputStream fout = new FileOutputStream(b);
	                            out = new OutputStreamWriter(fout,"UTF8");
	                            while ((line = br.readLine())!= null){
	                                text.append(line).append("\n");
	                                
	                            }
	                        }
				
				String t=text.toString();
				System.out.println(t);
				out.write(t);
				
				out.close();
			}
			
			catch (Exception e) {
				}
		}
}

